workspace(name = "rules_foreign_cc_examples")

local_repository(
    name = "rules_foreign_cc",
    path = "..",
)

load("@rules_foreign_cc//foreign_cc:repositories.bzl", "rules_foreign_cc_dependencies")

rules_foreign_cc_dependencies(register_built_pkgconfig_toolchain = True)

load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace")

bazel_skylib_workspace()

load("//deps:repositories.bzl", "repositories")

repositories()

load("//deps:deps_android.bzl", "deps_android")

deps_android()

load("//deps:deps_jvm_external.bzl", "deps_jvm_external")

deps_jvm_external()

load("@rules_python//python:repositories.bzl", "py_repositories", "python_register_toolchains")

py_repositories()

load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps")

protobuf_deps()

python_register_toolchains(
    name = "python_3_10",
    python_version = "3.10",
)

load("@rules_python//python:pip.bzl", "pip_parse")

pip_parse(
    name = "pip",
    python_interpreter_target = "@python_3_10_host//:python",
    requirements_lock = "//:requirements_lock.txt",
)

load("@pip//:requirements.bzl", "install_deps")

install_deps()

local_repository(
    name = "rules_foreign_cc_examples_third_party",
    path = "third_party",
)

load("@rules_foreign_cc_examples_third_party//:repositories.bzl", examples_third_party_repositories = "repositories")

examples_third_party_repositories()

load("@rules_foreign_cc_examples_third_party//:setup.bzl", examples_third_party_setup = "setup")

examples_third_party_setup()

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

http_archive(
    name = "bazelci_rules",
    sha256 = "eca21884e6f66a88c358e580fd67a6b148d30ab57b1680f62a96c00f9bc6a07e",
    strip_prefix = "bazelci_rules-1.0.0",
    url = "https://github.com/bazelbuild/continuous-integration/releases/download/rules-1.0.0/bazelci_rules-1.0.0.tar.gz",
)

load("@bazelci_rules//:rbe_repo.bzl", "rbe_preconfig")

# Creates a default toolchain config for RBE.
# Use this as is if you are using the rbe_ubuntu16_04 container,
# otherwise refer to RBE docs.
rbe_preconfig(
    name = "buildkite_config",
    toolchain = "ubuntu1804-bazel-java11",
)

http_archive(
    name = "build_bazel_apple_support",
    sha256 = "100d12617a84ebc7ee7a10ecf3b3e2fdadaebc167ad93a21f820a6cb60158ead",
    url = "https://github.com/bazelbuild/apple_support/releases/download/1.12.0/apple_support.1.12.0.tar.gz",
)

http_archive(
    name = "build_bazel_rules_apple",
    sha256 = "ed432a2d5929452748bd53a4ff9e652f2332283eb3d7ffad6cb63aab96a06301",
    url = "https://github.com/bazelbuild/rules_apple/releases/download/3.4.0/rules_apple.3.4.0.tar.gz",
)

load(
    "@build_bazel_rules_apple//apple:repositories.bzl",
    "apple_rules_dependencies",
)

apple_rules_dependencies()

load(
    "@build_bazel_rules_swift//swift:repositories.bzl",
    "swift_rules_dependencies",
)

swift_rules_dependencies()

load(
    "@build_bazel_rules_swift//swift:extras.bzl",
    "swift_rules_extra_dependencies",
)

swift_rules_extra_dependencies()

load(
    "@build_bazel_apple_support//lib:repositories.bzl",
    "apple_support_dependencies",
)

apple_support_dependencies()

load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")

maybe(
    http_archive,
    name = "rules_rust",
    integrity = "sha256-8TBqrAsli3kN8BrZq8arsN8LZUFsdLTvJ/Sqsph4CmQ=",
    urls = ["https://github.com/bazelbuild/rules_rust/releases/download/0.56.0/rules_rust-0.56.0.tar.gz"],
)

load("@rules_rust//rust:repositories.bzl", "rules_rust_dependencies", "rust_register_toolchains")

rules_rust_dependencies()

rust_register_toolchains()

load("@rules_rust//crate_universe:repositories.bzl", "crate_universe_dependencies")

crate_universe_dependencies()

load("@rules_rust//crate_universe:defs.bzl", "crate", "crates_repository", "splicing_config")

crates_repository(
    name = "rust_example",
    annotations = {
        # zlib-ng-sys's build script invokes cmake, so we need to make cmake available.
        # Fortunately, rules_foreign_cc has a cmake toolchain we can use.
        "libz-ng-sys": [crate.annotation(
            # Setting build_script_data makes the files available on disk when the rule runs.
            build_script_data = ["@rules_foreign_cc//toolchains:current_cmake_toolchain"],
            build_script_env = {
                # The toolchain supplies a value of $(CMAKE) which is an execroot-relative path, so we need to prefix it with $${pwd}/ because build scripts don't typically run in the execroot unlike most bazel rules, for improved compatibility with Cargo.
                "CMAKE": "$${pwd}/$(CMAKE)",
            },
            # Setting build_script_toolchains makes makefile variable substitution work so that we can reference $(CNAME) in attributes.
            build_script_toolchains = ["@rules_foreign_cc//toolchains:current_cmake_toolchain"],
        )],
    },
    cargo_lockfile = "//rust:Cargo.Bazel.lock",
    lockfile = "//rust:cargo-bazel-lock.json",
    packages = {
        "libz-ng-sys": crate.spec(
            version = "=1.1.20",
        ),
    },
    splicing_config = splicing_config(
        resolver_version = "2",
    ),
)

load(
    "@rust_example//:defs.bzl",
    rust_example_crate_repositories = "crate_repositories",
)

rust_example_crate_repositories()
